package cn.lzd.mr.case1;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Created by lzd on 2018/5/31.
 */
public class RDemo extends Reducer<Text, Bean, NullWritable, Bean> {

    @Override
    protected void reduce(Text key, Iterable<Bean> values, Context context) throws IOException, InterruptedException {
        int upflow = 0;
        int downflow = 0;

        for (Bean bean : values) {
            upflow += bean.getUpflow();
            downflow += bean.getDownflow();
        }

        context.write(NullWritable.get(), new Bean(upflow, downflow, key.toString()));
    }
}
